<?php // Start with output buffering and includes

ob_start();
require_once("init.php");
include("open_labs.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
	<title>Grinnell College Campus Technology Map</title>
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	
	<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
	<meta name="author" content="Dylan J. Sather" />
	<meta name="revised" content= <?php

	/* This script checks the date_modified file to give the date at which a file on the 
	   map was last modified, thus giving us the date at which the map was last revised */

	$date_file = "/home/satherdy/map_files/index_date_modified";
	$fh = fopen($date_file, 'r');
	$date = fread($fh, filesize($date_file));
	$date = trim($date);
	fclose($fh);
	print "\"Dylan J. Sather, $date\" />";

	?>

	<meta name="description" content="Grinnell College Campus Technology Map" />
	<meta name="keywords"
		content="Grinnell College, TC Corps, Technology Consultant,
			Computer lab, Map, Dylan J. Sather" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<meta http-equiv="Content-Script-Type" content="text/javascript" />
	<link rel="stylesheet" type="text/css" href="css/labmap.css" />

	<!-- IE8 fixed CSS issues, so we only want to use the IE styles on <= IE7 --> 
	<!--[if lte IE 7]>
		<link rel="stylesheet" type="text/css" href="css/ie.css" />
	<![endif]-->

	<script src="jquery/jquery-1.2.6.js" type="text/javascript"></script>
	<script src="jquery/ui.core.js" type="text/javascript"></script>
	<script src="jquery/ui.tabs.js" type="text/javascript"></script>
	<script src="javascript/toggle.js" type="text/javascript"></script>
	<script src="javascript/bubble.js" type="text/javascript"></script>
	<script type="text/javascript">
            $(function() {
		$('#fade > ul').tabs({ selected: <?php
		
		/* This script checks to see if the POST or GET variable 'tab_select' has a value; if it
		does, print the value; if it doesn't, print the default value of 0. This allows the
		map to select different active tabs based on user action. For instance, if someone
		is trying to log in, once they click the submit button, the page refreshes and she's
		presented with the same logon tab (with a message of success or failure). It wouldn't
		make sense to have the first tab appear, forcing her to navigate back to the Login tab */

		if (isset($_POST['tab_select'])) {
			print "{$_POST['tab_select']}"; 
		}
		else if (isset($_GET['tab_select'])) {
			print "{$_GET['tab_select']}";
		}
		else { 
			print "0"; // First tab (default)
		}

		?> });
                $('#fade > ul').tabs({ fx: { opacity: 'toggle' } }); // Nice fade effect
            });

	</script>
      </head>	   

<body>
	<div class="wrapper"> <!-- WRAPPER div -->

		<div class="header"> <!-- HEADER div -->
		  <img src="pictures/header.png" alt="Header -- Grinnell College Technology Map" />
		</div> <!-- End HEADER div -->

		<div id="fade" class="main"> <!-- START MAIN CONTAINER div -->
	  	  <ul>
	   	    <li class="inline bubbleInfo">
		      <a class="tabs trigger" href="#tab1">Computer Labs</a>
			<div class="hover_popup">
			  <p class="lab_popup">Check available computer labs</p>
			</div>
		    </li>
	   	    <li class="inline bubbleInfo">
		      <a class="tabs trigger" href="#tab2">Printers</a>
			<div class="hover_popup">
			  <p class="printer_popup">Check available printers</p>
			</div>
		    </li>
	   	    <li class="inline bubbleInfo">
		      <a class="tabs trigger" href="#tab3">General Information</a>
			<div class="hover_popup">
			  <p class="general_info_popup">Toner information and other resources</p>
			</div>		
		    </li>
	   	    <li class="inline bubbleInfo">
		      <a class="tabs trigger" href="#tab4">Search for labs</a>
			<div class="hover_popup">
			  <p class="search_popup">Search for labs by availability, software, geography...</p>
			</div>
		    </li>
	   	    <li class="inline bubbleInfo">
		      <a class="tabs trigger" href="#tab5">Login</a>
			<div class="hover_popup">
			  <p class="login_popup">For Helpdesk Staff</p>
			</div>
		    </li>
		    <li class="inline bubbleInfo">
		      <a class="tabs trigger" href="#tab6">Feedback/Report a Bug</a>
			<div class="hover_popup">
			  <p class="feedback_popup">Let us know what you think!</p>
			</div>
		    </li>
		  </ul>	

			<div id="tab1"> <!-- Start COMPUTER LAB MAP div -->
				<p>
				  Hover your mouse over a lab to find out more information about it
				</p>

				<?php // labs.php -- Display open/closed labs

				include("labs.php");				  

				?>

			</div> <!-- End COMPUTER LAB MAP div -->

			<div id="tab2"> <!-- Start PRINTER MAP div -->
				<p>
				  Hover your mouse over a printer to find out more information about it
				</p>

				<?php // printers.php -- Display available/unavailable printers

				include("printers.php");

				?>

			</div> <!-- End PRINTER MAP div -->

			<div id="tab3"> <!-- Start GENERAL INFO div -->

				<div class="offset"> <!-- Start OFFSET div -->

					<?php // lab_info.php -- Display general lab information

					include("lab_info.php");

					?>

				</div> <!-- End OFFSET div -->

			</div> <!-- End GENERAL INFO div -->

			<div id="tab4"> <!-- LAB SEARCH div -->

				<div class="offset"> <!-- Start OFFSET div -->

				<?php // search.php -- allows users to search for labs based on given criteria

					include("search.php");

				?>
		
				</div> <!-- End OFFSET div -->

			</div>  <!-- End LAB SEARCH div -->

			<div id="tab5"> <!-- LOGIN div -->

				<div class="offset"> <!-- OFFSET div -->

					<?php // login.php -- allows authorized users to login to the system

					// First, check if the user is already logged in (i.e. if the cookie is already set)

					if (isset($_COOKIE['login'])) {

						print "<p>Thanks, dude. You're logged in</p>
						<p><a href=\"logout.php\">Logout</a></p>";
					}

					else {

					/* Check to see if the form has been submitted first. Obviously this won't be the case when the user first visits the page, so 
					   we go to the else clause at the bottom */
						if (isset($_POST['submit'])) {

							// Now, check to see if the user submitted any information
							if ( (!empty($_POST['username'])) && (!empty($_POST['password'])) ) {
	
								// Finally, check to see if the username and password submitted match those on file
								if ( ($_POST['username'] == 'helpdesk') && ($_POST['password'] == 'helpdesk') ) {

									// And if everything is cool... set a cookie and refresh
									setcookie('login', 'successful', time()+3600); // The cookie expires after one hour
									header ('Location: http://tcdb.grinnell.edu/map');
								}

								else {
									header ('Location: http://tcdb.grinnell.edu/login.php'); // Redirect to login.php
								}
							}

							else { 
								header ('Location: http://tcdb.grinnell.edu/login.php'); // Redirect to login.php
							}
						}

						else {

							// Display the login form
							print "<h2>Authorized users can login below</h2>\n";

							print "<form action=\"login.php\" method=\"post\">
								<p>Username: <input type=\"text\" name=\"username\" size=\"20\" /> <br />
	   							Password: <input type=\"password\" name=\"password\" size=\"20\" /> <br />
       								<input type=\"submit\" name=\"submit\" value=\"Log In\" /></p></form>\n";
  						}
					}

					?>

				</div> <!-- End OFFSET div -->

			</div>  <!-- End LOGIN div -->

			<div id="tab6"> <!-- Start FEEDBACK div -->

				<div class="offset"> <!-- Start OFFSET div -->
				
				<p>This map is a constant work in progress. With that in mind, if you have any suggestions or would like to report a bug, please e-mail me at</p>
				<p><span class="codedirection email_color">moc.liamg@rehtas.nalyd</span></p>
				<p>For those brave in spirit, you can also check out the <a href="http://code.google.com/p/gctechmap/source/browse/#svn/trunk">source code</a>. You can download the source <a href="stats/source_download_count.php">here</a></p>
				
				<?php // show download count only to authorized users

				if (isset($_COOKIE['login'])) {
					 print "<p>The source has been downloaded ";
				
					 // Reads from download count file
		             		 readfile("http://tcdb.grinnell.edu/map/stats/source_downloads");
					 print " times</p>\n";
                                }

				?>

			</div> <!-- End OFFSET div -->
		
			</div> <!-- End FEEDBACK div -->

		</div> <!-- End MAIN CONTAINER div -->

		<!-- Start footer -->
	  	<p id="footer">
	    	  Grinnell College Technology Consultant Corps
		    <br />
		  Campus image courtesy of Mark Root-Wiley
		    <br />
		  This page <a href="validate.php">validates</a> as <a href="http://www.w3.org/TR/xhtml1/">XHTML 1.0 Strict</a>. The source code can be found at our <a href="http://code.google.com/p/gctechmap/source/browse/#svn/trunk">Google code page</a>
		</p>

	</div> <!-- End WRAPPER div -->

</body>

</html>

<?php // End by flushing output

ob_end_flush();

?>
